package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class Main2Activity extends AppCompatActivity {

    private static final String TAG = "Main2Activity";
    private BlankFragment blankFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);


        //管理者
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();

        //在提交之前操作
        blankFragment = new BlankFragment();
        BlankFragment2 blankFragment2 = new BlankFragment2();
        //1,容器id 2,要添加的对象
        fragmentTransaction.add(R.id.fl,blankFragment);
//        fragmentTransaction.add(R.id.fl2,blankFragment2);

        //替换
//        fragmentTransaction.replace(R.id.fl,blankFragment2);

        //fragmentTransaction.remove(blankFragment);  //空

        //显示  和  隐藏
//        fragmentTransaction.hide(blankFragment);
//        fragmentTransaction.show(blankFragment);

        fragmentTransaction.commit();


    }

    public void remove(View view) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.remove(blankFragment);
        fragmentTransaction.commit();

    }

    public void hide(View view) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.hide(blankFragment);
        fragmentTransaction.commit();
    }

    public void show(View view) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.show(blankFragment);
        fragmentTransaction.commit();
    }
}
